package com.apes.fn.server.servicePlan.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @program:
 * @description:
 * @author: lws
 * @create: 2023/3/20 11:35
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ClientInvoiceRules.CONST_TABLE_NAME)
public class ClientInvoiceRules extends Model {
    public static final  String CONST_TABLE_NAME = "CLIENT_INVOICE_RULES";

    @Id
    @Column(name = "id", length = 30)
    @Comment("客户开票规则编码")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "客户开票规则", padding = 7)
    private String id;

    @Comment("单位客户")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "customer_id", referencedColumnName = "id")
    private PartyRole customer;

    @Comment("开票方公司")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    private PartyRole company;

    @Comment("开票方门店")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false)
    private Dept dept;

    @OneToMany(mappedBy = "clientInvoiceRules", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<ClientInvoiceRulesItem> clientInvoiceRulesItems = new ArrayList<ClientInvoiceRulesItem>(); //从表
}
